package com.woniu.airent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.airent.dto.MyHouseDto;
import com.woniu.airent.mapper.MyHouseMapper;
import com.woniu.airent.service.MyHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 功能描述:<br>
 * 〈〉
 *
 * @author EDZ
 * @create 2020/10/10
 * @since 1.0.0
 */
@Service
public class MyHouseServiceImpl implements MyHouseService {

    @Autowired
    MyHouseMapper myHouseMapper;

    public static final int PAGE_SIZE = 2;

    @Override
    public PageInfo<MyHouseDto> findHouseColByPages( Integer userId,String houseResource, Integer selectByPrice,Integer selectByDate ,Integer colPageNum) {
        PageHelper.startPage(colPageNum,PAGE_SIZE);
        List<MyHouseDto> houseColDtos=myHouseMapper.selectHouseColByPages(userId,houseResource,selectByPrice,selectByDate);
        PageInfo<MyHouseDto> pageInfo=new PageInfo<>(houseColDtos);
        return pageInfo;
    }

    @Transactional
    @Override
    public Integer removeHouseColByColId(int colId) {
        return  myHouseMapper.deleteHouseColByHouseId(colId);
    }

    @Transactional
    @Override
    public int insertHouseCollection( MyHouseDto myHouseCollectionDto) {
        return myHouseMapper.insert(myHouseCollectionDto);
    }

    @Override
    public Integer findHouseIsCollection(Integer userId, Integer houseId) {
        return myHouseMapper.selectHouseIsCollection(userId,houseId);
    }

    @Override
    public void addCollect(Integer userId, Integer houseId) {
        myHouseMapper.insertMyCollection(userId,houseId);
    }

    @Override
    public void removeMyCollection(Integer userId, Integer houseId) {
        myHouseMapper.deleteHouseColByHouseIdAndUserId(userId,houseId);
    }

}
